#include "Socket.hpp"
#include <cstdlib>
#include <sys/socket.h>
#include <unistd.h>
#include <stdio.h>

namespace wd
{
Socket::Socket()
:_socketFd(creatFd())
{}

Socket::Socket(int fd)
:_socketFd(fd)
{}

Socket::~Socket(){
    close(_socketFd);
}

int Socket::getFd()const{
    return _socketFd;
}

void Socket::shotdownWrite(){
    int ret = shutdown(_socketFd,SHUT_WR);
    if (ret <0){
        perror("shutdown");
        return;
    }
}

int Socket::creatFd(){
    int socketfd = socket(AF_INET,SOCK_STREAM,0);
    if(socketfd <0){
        perror("socket");
        exit(EXIT_FAILURE);
    }
    return socketfd;
}

}//end of namespace
